package jobs.job3.classloaderdemo.server.zkutil;
import org.I0Itec.zkclient.ZkClient;

//将一个服务地址注册到zookeeper上
public class ServiceRegistrationClient {
    String rootPath = "/calculationNodes";
    ZkClient zkClient;

    //    链接zookeeper集群
    public void connectZk() {
        zkClient = new ZkClient("localhost:2181");
        if (!zkClient.exists(rootPath)) zkClient.createPersistent(rootPath);
    }

    //    将服务地址注册到zookeeper
    public void saveServerInfo(String ip, String port) {
        String sequencePath = zkClient.createEphemeralSequential(rootPath + "/node", ip + ":" + port);
        System.out.println("向zk注册成功, 计算节点 " + sequencePath + "\t" + ip + ":" + port + " 可以接受计算任务");
    }


}
